home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / WWShaders / WWGlowingGrid.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  2.9 KB  |  97 lines

  1. /* adapted from Larry Gritz's antialiased screen shader (see BMRTShaders/BMAntialiasedScreen and RCGlow)
  2.  */
  3. /*
  4.  * WWGrid.sl -- shader that makes a glowing screen with potentially different grids in s and t
  5.  *
  6.  * DESCRIPTION:
  7.  *   Makes a surface that looks like a glowing screen.  Strips of metal run
  8.  *   parallel to lines of s and t.  You can adjust the Ka, Kd, Ks, etc.
  9.  *   to change the material appearance.  This texture antialiases pretty
  10.  *   well, even with only one sample per pixel.
  11.  *
  12.  * PARAMETERS:
  13.  *   Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader
  14.  *   frequency - how many cycles of screen in st space
  15.  *   density - how much of each cycle is opaque?
  16.  *
  17.  * AUTHOR: hacked by wave (again, from an original shader by Larry Gritz)
  18.  *
  19.  */
  20.  
  21.  
  22.  
  23. #define boxstep(a,b,x) (clamp(((x)-(a))/((b)-(a)),0,1))
  24. #define MINFILTERWIDTH 1.0e-7
  25.  
  26.  
  27.  
  28. surface
  29. WWGlowingGrid (float Ka = 1, Kd = 0.75, Ks = 0.4, roughness = 0.1;
  30.             color specularcolor = 1;
  31.             float sDensity = 0.2, sFrequency = 2, 
  32.                       tDensity = .1, tFrequency = 10,
  33.                       attenuation = 2)
  34. {
  35.   point Nf;     /* Forward facing Normal vector */
  36.   point IN;     /* normalized incident vector */
  37.   float d;      /* Density at the sample point */
  38.   float ss, tt; /* s,t, parameters in phase */
  39.   float swidth, twidth, sGWF, tGWF, w, h;
  40.   point NN = normalize(N);
  41.   point II = normalize(I);
  42.   float falloff = II.NN;    /* Direct incidence has cosine closer to 1.*/
  43.  
  44.  
  45.   /* Compute a forward facing normal */
  46.   IN = normalize (I);
  47.   Nf = faceforward (normalize(N), I);
  48.  
  49.   /* Determine how wide in s-t space one pixel projects to */
  50.   swidth = max (abs(Du(s)*du) + abs(Dv(s)*dv), MINFILTERWIDTH) * sFrequency;
  51.   twidth = max (abs(Du(t)*du) + abs(Dv(t)*dv), MINFILTERWIDTH) * tFrequency;
  52.  
  53.   /* Figure out where in the pattern we are */
  54.   ss = mod (sFrequency * s, 1);
  55.   tt = mod (tFrequency * t, 1);
  56.  
  57.   /* Figure out where the strips are. Do some simple antialiasing. */
  58.   sGWF = sDensity*0.5;
  59.   if (swidth >= 1)
  60.   {  w = 1 - 2*sGWF;
  61.   }
  62.   else 
  63.   {  w =   clamp (boxstep(sGWF-swidth, sGWF, ss), max(1-sGWF/swidth, 0), 1)
  64.        - clamp (boxstep(1-sGWF-swidth, 1-sGWF, ss), 0, 2*sGWF/swidth);
  65.   }
  66.  
  67.   tGWF = tDensity*0.5;
  68.   if (twidth >= 1)
  69.   {  h = 1 - 2*tGWF;
  70.   }
  71.   else 
  72.   {  h =   clamp (boxstep(tGWF-twidth, sGWF, tt), max(1-tGWF/twidth, 0), 1)
  73.      - clamp (boxstep(1-tGWF-twidth, 1-tGWF, tt), 0, 2*tGWF/twidth);
  74.   }
  75.  
  76.   d = 1 - w*h;
  77.   Oi = d;
  78.   if (d > 0) 
  79.   {  if (falloff < 0) 
  80.      {  /* Back of sphere only */
  81.         /* Normalize falloff by lengths of I and N */
  82.         falloff = falloff * falloff / (II.II * NN.NN) ;
  83.         falloff = pow(falloff, attenuation);
  84.         Ci = Cs * falloff;
  85.         Oi = falloff;
  86.      }
  87.      else 
  88.      {  Oi = 0;
  89.         Ci = 0; /* wave added this line to avoid old bug in rendrib... */
  90.      }
  91.   }
  92.    else
  93.    {  Oi = 0;
  94.       Ci = 0; /* wave added this line to avoid old bug in rendrib... */
  95.    }
  96. }
  97.